package com.project.forum.controller;

import com.project.forum.common.AppResult;
import com.project.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Time:11:22
 */
//定义一级映射路径
@Api(tags = "测试类的相关接口")
@RequestMapping("/test")
//表示返回的结果是数据而不是url
@RestController
public class TestController {
    @ApiOperation("测试接口1.显示你好spring boot")
    @GetMapping ("hello")
    public String hello(){
        return "hello,Spring boot...";
    }

    @ApiOperation(("测试接口4，按传入的姓名显示你好信息"))
    @PostMapping("/helloByName")
    public AppResult helloByName(@ApiParam(value = "姓名") @RequestParam("name") String name){
        return AppResult.success("hello:"+name);
    }
    @ApiOperation("测试接口2.显示抛出异常信息")

    @GetMapping("/exception")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @ApiOperation("测试接口3.显示自定义异常信息")

    @GetMapping("/appException")
    public AppResult testApplicationException(){
        throw new ApplicationException("这是一个ApplicationException...");
    }
}


